﻿using System;
using Spanner;

namespace SpannerWebSite
{
    internal class ThirdPartyDemo : MiniWebApp
    {
        // A very simple wrapper around some jQuery functionality.
        // A real wrapper would be much bigger!
        public static ExternalNonSpannerLibraryModel JQCore =
            new ExternalNonSpannerLibraryModel("JQCore", @"http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js");

        public class JQModel : LibraryModel
        {
            // The API for the Counter global model.
            public class Elts { }
            public Expr<Elts> Find(Expr<string> query) { return JSExpr<Elts>("$(#)", query); }
            public Expr<Elts> FadeIn(Expr<Elts> elts) { return JSExpr<Elts>("#.fadeIn()", elts); }
            public Expr<Elts> FadeOut(Expr<Elts> elts) { return JSExpr<Elts>("#.fadeOut()", elts); }

            // The constructor provides the implementation.
            public JQModel() : base("JQ", null /* No init. act. */, JQCore) { }
        }

        internal static JQModel JQ = new JQModel();

        internal ThirdPartyDemo()
        {
            Name = "ThirdPartyDemo";

            PageTitle = "Third Party Demo";

            var helloID = HtmlID("Hello");

            var fade = Procedure("fade", Do(JQ.FadeIn(JQ.FadeOut(JQ.Find("#" + helloID.ToString())))));

            Content = Div(
                P("Hello!").WithID(helloID),
                Button("Fade").KoClick(fade)
            );

            Dependencies = new Model[] { JQ };
        }
    }
}
